package com.gofaraway.service.student.base;

import com.gofaraway.common.util.lambda.LambdaUtil;

import java.lang.reflect.Array;
import java.util.*;

import static java.lang.Math.min;

/**
 * 匿名内部类
 * @author ChenPeng
 * @Date 2024/6/1 11:10
 */
public class Demo01 {

    int i;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Demo01 demo01 = (Demo01) o;
        return i == demo01.i;
    }

    @Override
    public int hashCode() {
        return Objects.hash(i);
    }
}

class Solution implements Cloneable{

    public int trap(int[] height) {


        List<int[]> list = Arrays.asList(height);
        for (int[] ints : list) {

        }
        int rongliang = 0;


        for (int i : height) {



            for (int j : height) {
                if (j <= i) {
                    break;
                }
                //后节点 比前节点高 无法接水
                if (height[i + 1] >= height[i]) {
                    break;
                }
                if (height[j] < height[i]) {
                    rongliang = height[i] - height[j];
                } else {
                    i = j + 1;
                    break;
                }
            }
        }
        return rongliang;
    }

    public int trap1(int[] height) {
        int res = 0;

        for (int i = 0; i < height.length; i++) {
            int left = 0;

            for (int j = 0; j <= i; j++) {
                if (height[j] > left) {
                    left = height[j];
                }
            }

            int right = 0;
            for (int j = i; j < height.length; j++) {
                if (height[j] > right) {
                    right = height[j];
                }
            }

            res = res + ( Math.min(left, right) - height[i]);
        }

        return res;
    }


    public static void main(String[] args) throws CloneNotSupportedException {
        Solution solution = new Solution();

        Object clone = solution.clone();
        int[] array = {0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1};
        int trap = solution.trap(array);
        System.out.println(trap);
    }

    @Override
    public Solution clone() {
        try {
            return (Solution) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }
}
